﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace WpfWordsLearner.Converters
{
	public class BoolToVisibilityConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			bool visState = (bool)value;
			return visState == true ? System.Windows.Visibility.Visible : System.Windows.Visibility.Hidden;
		}

		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			throw new NotImplementedException();
		}
	}

	public class BoolToImageConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			bool success = (bool)value;
			System.Reflection.Assembly asmb = System.Reflection.Assembly.GetExecutingAssembly();
			System.IO.Stream stream = success == true ? asmb.GetManifestResourceStream("WpfWordsLearner.Graphics.success.jpg") :
				asmb.GetManifestResourceStream("WpfWordsLearner.Graphics.cross.gif");
			if (stream != null)
			{
				byte[] photo = new byte[stream.Length];
				stream.Read(photo, 0, photo.Length);
				BitmapImage image = new BitmapImage();
				image.BeginInit();
				image.StreamSource = new System.IO.MemoryStream(photo);
				image.EndInit();
				return image;
			}
			return null;
		}

		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			throw new NotImplementedException();
		}
	}
}
